package com.dingwen.treasure.manage.controller;

import com.dingwen.treasure.base.pojo.vo.Result;
import com.dingwen.treasure.manage.dto.SysMenuDto;
import com.dingwen.treasure.model.entity.mybatisplus.SysMenu;
import com.dingwen.treasure.model.vo.SysMenuVo;
import com.dingwen.treasure.mybatisplus.controller.AbstractBaseControllerMybatisPlusImpl;
import com.dingwen.treasure.mybatisplus.service.SysMenuService;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * 　SysMenuController
 * 　@author dingwen
 * 　@date 2022/6/21
 */
@Api(tags = "系统菜单,基于mybatis-plus封装BaseController")
@ApiSupport(author = "dingwen")
@Slf4j
@RestController
@RequestMapping("sys/menu")
public class SysMenuController extends AbstractBaseControllerMybatisPlusImpl<SysMenu, SysMenuDto, SysMenuVo> {


    /**
     * sysMenuService
     */
    @Resource
    private SysMenuService sysMenuService;

    /**
     * 按用户id获取系统菜单
     *
     * @param userId 用户id
     * @return {@link Result}<{@link List}<{@link SysMenu}>>
     */
    @ApiOperation("根据用户Id获取菜单")
    @GetMapping("/feign/{userId}")
    Result<List<SysMenu>> getSysMenusByUserId(@PathVariable Long userId) {
        return success(sysMenuService.getSysMenusByUserId(userId));
    }

    /**
     * 获取树系统菜单
     *
     * @param userId 用户id
     * @return {@link Result}<{@link List}<{@link SysMenuVo}>>
     */
    @ApiOperation("获取树系统菜单")
    @GetMapping("/feign/tree/{userId}")
    Result<List<SysMenuVo>> getSysMenusForTree(@PathVariable Long userId) {
        return success(sysMenuService.getSysMenusForTree(userId));
    }

    /**
     * 默认开启 BO 到 VO 的转换
     *
     * @return {@link Boolean}
     */
    @Override
    public Boolean enableBoToVo() {
        return Boolean.FALSE;
    }
}
